﻿using System;
using System.Reflection;
using System.Windows;
using System.Windows.Media;
using Oxage.Common;
using Oxage.Printing.Models;

namespace Oxage.Printing
{
	public partial class Settings
	{
		#region Application
		public static string ApplicationName
		{
			get
			{
				return string.Format("{0} v{1}", ProductName, ProductVersion);
			}
		}

		public static string ProductName
		{
			get
			{
				string result = null;
				Assembly assembly = Assembly.GetExecutingAssembly();
				object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
				if (attributes != null && attributes.Length > 0)
				{
					result = (attributes[0] as AssemblyTitleAttribute).Title;
				}
				return result;
			}
		}

		public static string ProductVersion
		{
			get
			{
				Assembly assembly = Assembly.GetExecutingAssembly();
				Version version = assembly.GetName().Version;
				string result = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build);
				return result;
			}
		}
		#endregion

		#region Registry
		static Settings()
		{
			Config.DefaultCache = false;
			Config.DefaultSource = ConfigSource.Registry;
			Config.RegistryRootPath = @"Software\Oxage\xbprint\";
		}

		public static bool Debug
		{
			get
			{
				bool result;
				return Config.Get("Debug", out result) ? result : false;
			}
			set
			{
				Config.Set("Debug", value);
			}
		}

		public static double MarginLeft
		{
			get
			{
				double result = 0;
				return Config.Get("MarginLeft", out result) ? result : 25;
			}
			set
			{
				if (value >= 0)
				{
					Config.Set("MarginLeft", value);
				}
			}
		}

		public static double MarginRight
		{
			get
			{
				double result = 0;
				return Config.Get("MarginRight", out result) ? result : 25;
			}
			set
			{
				if (value >= 0)
				{
					Config.Set("MarginRight", value);
				}
			}
		}

		public static double MarginTop
		{
			get
			{
				double result = 0;
				return Config.Get("MarginTop", out result) ? result : 25;
			}
			set
			{
				if (value >= 0)
				{
					Config.Set("MarginTop", value);
				}
			}
		}

		public static double MarginBottom
		{
			get
			{
				double result = 0;
				return Config.Get("MarginBottom", out result) ? result : 25;
			}
			set
			{
				if (value >= 0)
				{
					Config.Set("MarginBottom", value);
				}
			}
		}

		public static Stretch Stretch
		{
			get
			{
				Stretch result;
				return Config.Get<Stretch>("Stretch", out result) ? result : Stretch.Uniform;
			}
			set
			{
				Config.Set<Stretch>("Stretch", value);
			}
		}

		public static PaperOrientations PaperOrientation
		{
			get
			{
				PaperOrientations result = PaperOrientations.Portrait;
				return Config.Get<PaperOrientations>("PaperOrientation", out result) ? result : PaperOrientations.Portrait;
			}
			set
			{
				Config.Set<PaperOrientations>("PaperOrientation", value);
			}
		}

		public static VerticalAlignment VerticalAlignment
		{
			get
			{
				VerticalAlignment result;
				return Config.Get<VerticalAlignment>("VerticalAlignment", out result) ? result : VerticalAlignment.Center;
			}
			set
			{
				Config.Set<VerticalAlignment>("VerticalAlignment", value);
			}
		}

		public static HorizontalAlignment HorizontalAlignment
		{
			get
			{
				HorizontalAlignment result;
				return Config.Get<HorizontalAlignment>("HorizontalAlignment", out result) ? result : HorizontalAlignment.Center;
			}
			set
			{
				Config.Set<HorizontalAlignment>("HorizontalAlignment", value);
			}
		}

		public static double PaperWidth
		{
			get
			{
				double result = 0;
				return Config.Get("PaperWidth", out result) ? result : 210;
			}
			set
			{
				if (value >= 0)
				{
					Config.Set("PaperWidth", value);
				}
			}
		}

		public static double PaperHeight
		{
			get
			{
				double result = 0;
				return Config.Get("PaperHeight", out result) ? result : 297;
			}
			set
			{
				if (value >= 0)
				{
					Config.Set("PaperHeight", value);
				}
			}
		}
		#endregion
	}
}
